<?php

namespace App\Services\Fund;

use App\Services\Fund\Withdraw\WithdrawLogic;
use App\Services\User\Token;
use App\Services\User\App;
use Request;

/**
 * 数字币冻结日志
 * Class Withdraw
 * @package App\Services\Fund
 */
class Withdraw
{


    /*
    $app_key = config('tpproject.yayi_admin_app_key');
        $token = (new Token())->hGetAll($data['token']);
        if($token['res']['status'] != SUCCESS_STATUS){
            return $token;
        }
        $find = (new App())->find(['app_key'=>$app_key]);
        if($find['res']['status'] != SUCCESS_STATUS){
            return $find ;
        }*/
    /*我的 - 申请提现*/
    public function applyDrawwith($data): array
    {
        $data = pick_array($data, ['token','card_id', 'money', 'pay_password', 'user_id', 'user_info']);
        ValidateWithdraw::checkValidate($data, [ 'card_id', 'money', 'pay_password', 'user_id']);
        return (new WithdrawLogic())->applyDrawwith($data);
    }

    /*我的 - 申请提现列表（分页）*/
     public function withdrawList($data): array
     {
         $data = init_array($data, ['user_id'=>0]);
         ValidateWithdraw::checkValidate($data, ['user_id']);
         return (new WithdrawLogic())->withdrawList($data);
     }
    //冻结资金列表
    public function freezeList($data)
    {
        $data = init_array($data, ['user_id'=>0]);
        ValidateWithdraw::checkValidate($data, ['user_id']);
        return (new WithdrawLogic())->freezeList($data);
    }
    //司机和企业的收入统计 今日收入 当月累计收入 总收入 余额 保证金 待收款 罚金
    public function earnings($data)
    {
        $data = init_array($data, ['user_id'=>0,'role_ids'=>'']);
        ValidateWithdraw::checkValidate($data, ['user_id','role_ids']);
        return (new WithdrawLogic())->earnings($data);
    }

    //车主端七日收入统计 当月收入统计
    public function driverIncomeStatistic($data)
    {
        $data = init_array($data, ['user_id'=>0]);
        ValidateWithdraw::checkValidate($data, ['user_id']);
        return (new WithdrawLogic())->driverIncomeStatistic($data);
    }

    //司机和企业的待收货运单
    public function dueInWaybills($data)
    {
        $data = init_array($data, ['user_id'=>0,'role_ids'=>'']);
        ValidateWithdraw::checkValidate($data, ['user_id','role_ids']);
        return (new WithdrawLogic())->dueInWaybills($data);
    }
    //司机的罚单列表
    public function penalty($data)
    {
        $data = init_array($data, ['user_id'=>0]);
        ValidateWithdraw::checkValidate($data, ['user_id']);
        return (new WithdrawLogic())->penalty($data);
    }
    //司机 的保证金列表
    public function margin($data)
    {
        $data = init_array($data, ['user_id'=>0]);
        ValidateWithdraw::checkValidate($data, ['user_id']);
        return (new WithdrawLogic())->margin($data);
    }

    //货主 冻结中资金 保证金 余额
    public function shipperMoney($data)
    {
        $data = init_array($data, ['user_id'=>0]);
        ValidateWithdraw::checkValidate($data, ['user_id']);
        return (new WithdrawLogic())->shipperMoney($data);
    }

    //货主 的保证金列表
    public function shipperMargin($data)
    {
        $data = init_array($data, ['user_id'=>0,'type'=>'']);
        ValidateWithdraw::checkValidate($data, ['user_id']);
        return (new WithdrawLogic())->shipperMargin($data);
    }

    //货主 待收货运单
    public function shipperDueIn($data)
    {
        $data = init_array($data, ['user_id'=>0]);
        ValidateWithdraw::checkValidate($data, ['user_id']);
        return (new WithdrawLogic())->shipperDueIn($data);
    }
    //----------------------------------后台管理---------------------------------------------------------------------------------
    /*管理员 - 获取提现列表*/
    public function adminWithdrawList($data): array
    {
        $data = init_array($data, ['keywords'=>0]);
        ValidateWithdraw::checkValidate($data, ['keywords']);
        return (new WithdrawLogic())->adminWithdrawList($data);
    }

    /*管理员 - 审核提现*/
    public function auditWithdraw($data): array
    {
        $data = init_array($data, ['id' => 0,'review_id' => 0, 'review_info' => [], 'status' => 0]);
        if (empty($data)) {
            return null_data($data, "参数不能为空！");
        }
        ValidateWithdraw::checkValidate($data, ['id','review_id', 'review_info']);
        return (new WithdrawLogic())->auditWithdraw($data);
    }

}
